import { nextTick } from 'vue'
import { defineStore } from 'pinia'
import type { RouterTypes } from '~/basic'
import defaultSettings from '@/settings'
import router, { constantRoutes } from '@/router'
export const useBasicStore = defineStore('basic',{
    state:()=>{
        return {



            allRoutes: constantRoutes,





             //keep-alive
            cachedViews: [] as Array<string>,
            cachedViewsDeep: [] as Array<string>,
            //other
            sidebar:{opened:true},


            settings:defaultSettings
        }
    },
    persist:{
        storage:localStorage,
        paths:[]
    },
    actions:{




























































    setToggleSideBar() {
        this.$patch((state) => {
          state.sidebar.opened = !state.sidebar.opened
        })
    },

    /*keepAlive缓存*/
    addCachedView(view){
        this.$patch((state)=>{
            if(state.cachedViews.includes(view)) return
            state.cachedViews.push(view)
        })
    },
    
    delCacheView(view){
        this.$patch((state)=>{
            const index=state.cachedViews.indexOf(view);
            index>-1 && state.cachedViews.splice(index,1)
        })
    },
         /*third  keepAlive*/
    addCachedViewDeep(view) {
        this.$patch((state) => {
          if (state.cachedViewsDeep.includes(view)) return
          state.cachedViewsDeep.push(view)
        })
      },
      delCacheViewDeep(view) {
        this.$patch((state) => {
          const index = state.cachedViewsDeep.indexOf(view)
          index > -1 && state.cachedViewsDeep.splice(index, 1)
        })
      }
    }
})